package com.smart4j.framework.thread.impl;

import com.smart4j.framework.thread.MyThreadLoacl;
import com.smart4j.framework.thread.Sequence;

/**
 * description: 使用自定义的 MyThreadLocal 实现线程之间变量不共享。
 * @version v1.0
 * @author w
 * @date 2018年10月16日下午9:57:06
 **/
public class SequenceC implements Sequence {
	
	private MyThreadLoacl<Integer> container = new MyThreadLoacl<Integer>(){
		@Override
		protected Integer initialValue() {
			return 0;
		};
	};
	
	
	@Override
	public int getNumber() {
		container.set(container.get()+1);
		return container.get();
	}
	
	public static void main(String[] args) {
		Sequence sequence = new SequenceC();
		
		ClientThread c1 = new ClientThread(sequence);
		ClientThread c2 = new ClientThread(sequence);
		ClientThread c3 = new ClientThread(sequence);
		
		c1.start();
		c2.start();
		c3.start();
	}
}
